﻿@model IList<ExamPlat.ViewModels.ViewUserInfo>
@{
    ViewBag.Title = "Index";
}

<div>
    <form action="/UserInfo/Index" method="post">
        <table>
            <tr>
                <td><input type="text" id="loginAccount" name="loginAccount" value="@ViewBag.LoginAccount" placeholder="登录帐号" /></td>
                <td style="padding-left:10px;"><input type="text" id="userName" name="userName" value="@ViewBag.UserName" placeholder="用户姓名" /></td>
                <td style="padding-left:10px;"><input class="btn btn-primary" type="submit" value="查询" /></td>
                <td style="padding-left:10px;"><input type="button" value="增加" id="btnAdd" class="btn btn-primary" /></td>
            </tr>
        </table>
    </form>
</div>
<div>
    <table style="width:600px;">
        <tr><th>用户姓名</th><th>登录帐号</th><th>用户角色</th><th>操作</th></tr>
        @{
            if (Model != null)
            {
                foreach (var item in Model)
                {
                    <tr><td>@item.UserName</td><td>@item.LoginAccount</td><td>@item.UserRole</td><td><a href="javascript:;" onclick="EditUserInfo(@item.ID)">修改</a> <span style="padding-left:10px;"><a href="javascript:;" onclick="DelUserInfo(@item.ID,'@item.UserName')">删除</a></span></td></tr>
                }
            }
        }
    </table>
</div>
<script type="text/javascript">
    function DelUserInfo(id, name) {
        if (confirm('确定要删除' + name + '？')) {
            $.ajax({
                type: "post",  //提交方式
                url: "Delete",//路径
                data: { "id": id},//数据，这里使用的是Json格式进行传输
                dataType: "json",
                success: function (result) {//返回数据根据结果进行相应的处理
                    alert(result.msg);
                    window.location.reload();
                }
            });
        }
    }

    function EditUserInfo(id) {
        window.location = "/UserInfo/Edit?id=" + id + "&searchAccount=" + $("#loginAccount").val() + "&searchName=" + $("#userName").val();
    }

    $(function () {
        $("#btnAdd").click(function () {
            window.location = "/UserInfo/Create?searchAccount=" + $("#loginAccount").val() + "&searchName=" + $("#userName").val();
        });
    });
</script>